有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Restlet和GAE过滤根路径

我有一段代码,当访问ROOT_URI时,我需要能够触发MyFilter:

private static final String ROOT_URI = "/";
private static final String ROOT_REST_URI = "/rest/";

@Override
public Restlet createInboundRoot() {
    Guice.createInjector(new GuiceConfigModule(this.getContext()),
            new SelfInjectingServerResourceModule());

    Router router = new Router(getContext());

    router.attach(ROOT_URI + "{id}", new GaeRedirector(getContext(), "{id}"));
    router.attach(ROOT_REST_URI, GaeRootServerResource.class);

    MyFilter mFilter = new MyFilter(getContext());
    MyFilter.setNext(router);

    return mFilter;
}

MyFilter仅在访问ROOT\u REST\u URI时触发。Restlet团队已经通过邮件组建议,我需要首先将路由放入根URI中

问题是,

  • ROOT_URI不在路由中,因为它在web中。xml,一个welcome-file设置指向索引。html。因此,当访问http://localhost:8080/时,它返回索引。html页面

我还尝试添加(作为根URI的路由,以使MyFilter在根URI上工作):

Directory directory = new Directory(getContext(), "war:///doc");
router.attach(ROOT_URI, directory);

然而,这个目录路由不适用于GAE。它似乎根本不会触发。使用此目录代码访问http://localhost:8080/,仍然是索引。显示html,不触发MyFilter

现在,如果我删除web中的<welcome-file>。xml。MyFilter被触发,但现在无法显示index.html。除非通过向请求中添加/index.html来明确说明

对于这种情况有什么解决方案


共 (1) 个答案

  1. # 1 楼答案

    我将尝试为目录设置默认索引名,如下所示:

    Directory directory = new Directory(getContext(), "war:///doc");
    directory.setIndexName("index.html");